<%@ page contentType="text/html; charset=utf-8" %>

<%@ include file="/WEB-INF/jsp/includeTop.jsp" %>

<form:form commandName="projectForm" target="tempFrame">
<table width="100%" border="0" cellpadding="0" cellspacing="5">
  <tr>
    <td valign="top">
      <table class="dbborder" width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td valign="bottom" class="blueTableBg">&nbsp;新增项目&nbsp;-&nbsp;项目基础信息</td>
        </tr>
        <tr>
          <td>
            <table width="100%" border="0" cellpadding="0" cellspacing="5">
              <tr>
                <td>
                  <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                    
                      <td class="dashTopLeft"><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                      <td class="dashTop" width=100%><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                      <td class="dashTopRight"><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                    </tr>
                    <tr>
                      <td class="dashLeft"><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                      <td align="center">
                        <table width="100%" border="0" cellpadding="0" cellspacing="3">
                        	
                          <tr>
                            <td width="114" height="20" class="globalText">项目编号(*)</td>
                            <td height="20" class="globalText">
                            	<input id="projectCode" type="text" class="txtbox" size="20" name="projectCode" value=""/>
                            </td>
                          </tr>
                          <tr>
                            <td width="114" height="20" class="globalText">项目名称(*)</td>
                            <td height="20" class="globalText">
                            	<input id="projectName" type="text" class="txtbox" size="20" name="projectName" value="" />
                            </td>
                          </tr>
                          <tr>
                            <td width="114" height="20" class="globalText">客户名称(*)</td>
                            <td height="20" class="globalText">
															<form:select path="customerIdSlt">
							               		<form:option value="-1" label="-请选择-"/>
							               		<form:options items="${projectForm.customers}" itemValue="code" itemLabel="name" />
						               		</form:select>
                            </td>
                          </tr>
                          <tr>
                            <td width="114" height="20" class="globalText">项目负责人(*)</td>
                            <td height="20" class="globalText">
                            	<input type="hidden" name="projectManagerId" id="projectManagerId"/>
                            	<input readonly="readonly" type="text" id="projectManagerPickedFrom" class="txtbox" size="20" value="" onclick="javascript:showRadioTree('<c:url value="/json/findAllOrgnizations.html"/>',this.id,setting);" />
                            </td>
                          </tr>
				                  <tr>
                            <td width="114" height="20" class="globalText">开始时间(*)</td>
                            <td width="114" height="20" class="globalText">
				                    	<input onclick="WdatePicker({minDate:'${nowDate}',dateFmt:'yyyy-MM-dd'});" type="text" readonly="readonly" class="txtbox" size="20" id="startDate" name="startDate" value="" />
                            </td>
				                  </tr>
				                  <tr>
                            <td width="114" height="20" class="globalText">结束时间(*)</td>
                            <td width="114" height="20" class="globalText">
				                    	<input onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'startDate\')}'})" type="text" readonly="readonly" class="txtbox" size="20" id="endDate" name="endDate" value="" />
                            </td>
				                  </tr>
                          <tr>
                            <td width="114" height="20" class="globalText">项目类型(*)</td>
                            <td height="20" class="globalText">
															<form:select path="projectCategoryIdSlt">
							               		<form:option value="-1" label="-请选择-"/>
							               		<form:options items="${projectForm.projectCategories}" itemValue="id" itemLabel="name" />
						               		</form:select>
                            </td>
                          </tr>
                          <tr>
                            <td width="114" height="20" class="globalText">项目描述 </td>
                          </tr>
                          <tr>
                            <td width="114" height="20" class="globalText" colspan="2">
                            	<textarea class="globalText" id="projectDescription" name="projectDescription" rows="5" cols="80"></textarea>                   	
                            </td>
                          </tr>
                          <tr>
                            <td align="center" colspan="2">
                              <table border="0" cellpadding="0" cellspacing="2">
                                <tr>
                                  <td><input type="button" name="saveBtn" class="btnStyle" value="  提交项目  "></td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table>
                      </td>
                      <td class="dashRight"><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                    </tr>
                    <tr>
                      <td class="dashBottomLeft"><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                      <td class="dashBottom" width=100%><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                      <td class="dashBottomRight"><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</form:form>

<script type="text/javascript">
<!--
$(document).ready(function() {
    var projectForm = $("form[id=projectForm]");
    var saveBtn = projectForm.find(":button[name=saveBtn]");

    saveBtn.click(function() {
    	document.getElementById("projectForm").action="<c:url value='newProject.html' />";
    	document.getElementById("projectForm").method="post";
    	
		  var projectCode = document.getElementById("projectCode").value.trim();
			if (validateEmpty(projectCode)) {
				alert("项目编号 不能为空");
				return false;
			}

			var projectName = document.getElementById("projectName").value.trim();
			if (validateEmpty(projectName)) {
				alert("项目名称 不能为空");
				return false;
			}
	
			var customerIdSlt = document.getElementById("customerIdSlt").value;
			if (customerIdSlt == -1) {
				alert("请选择 客户名称");
				return false;
			}
				
			var projectManagerPickedFrom = document.getElementById("projectManagerPickedFrom").value.trim();
			var projectManagerId = document.getElementById("projectManagerId").value;
			if (validateEmpty(projectManagerPickedFrom) || validateEmpty(projectManagerId)) {alert(projectManagerId);
				alert("项目负责人  不能为空");
				return false;
			}
	
			var startDate = document.getElementById("startDate").value;
			if (validateEmpty(startDate)) {
				alert("开始时间  不能为空");
				return false;
			}
	
			var endDate = document.getElementById("endDate").value;
			if (validateEmpty(endDate)) {
				alert("结束时间  不能为空");
				return false;
			}
	
			var projectCategoryIdSlt = document.getElementById("projectCategoryIdSlt").value;
			if (projectCategoryIdSlt == -1) {
				alert("请选择 项目类型");
				return false;
			}		 
		 
			projectForm.submit();
    });
});

var setting = {
		view : {
			dblClickExpand : false
		},
		data : {
			simpleData : {
				enable : true
			}
		},
		callback : {
			onDblClick:function(e, treeId, treeNode){
				if(!treeNode.isParent && !treeNode.isEmploy){
					var icon=treeNode.icon;
					treeNode.icon = "<c:url value='/css/zTreeStyle/img/loading.gif' />";
					$.fn.zTree.getZTreeObj(treeId).updateNode(treeNode);
					$.getJSON("<c:url value='/json/findAllChildEmployeesBy.html?orgCode=' />"+treeNode.id, function(jsonData){
						if(jsonData.length>0){
							var zTree = $.fn.zTree.getZTreeObj(treeId);
							for(var i=0;i<jsonData.length;i++){
								jsonData[i].isEmploy=true;
							}
							zTree.addNodes(treeNode, jsonData);
						}else{
							alert('未找到相关数据');
						}
						
						treeNode.icon = icon;
						$.fn.zTree.getZTreeObj(treeId).updateNode(treeNode);
					});
				}
			},
			onClick:function(e, treeId, treeNode){
				if(treeNode.isEmploy){
					var pickedFromObj = $('#projectManagerPickedFrom');
					pickedFromObj.attr('value', treeNode.name);
					$('#projectManagerId').val(treeNode.id);
				}
			}
		}
	};



function submitCallbackSuccess(obj){
	window.location="projectList.html";
}



//-->
</script>